#
# @lc app=leetcode.cn id=219 lang=python3
#
# [219] 存在重复元素 II
#

# @lc code=start
from collections import defaultdict
from typing import List


class Solution:
    def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
        cnt = {}
        for i,x in enumerate(nums):
            if x in cnt and i - cnt[x] <= k:
                return True
            cnt[x] = i
        return  False

# @lc code=end

